package com.bwie.controller;

import com.bwie.pojo.TbType;
import com.bwie.service.TbTypeService;
import com.bwie.utils.R;
import com.bwie.utils.Result;
import com.bwie.vo.PageInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @projectName: server-2211a-shop
 * @package: com.bwie.controller
 * @className: TbTypeController
 * @author: 杨珂
 * @description: TODO
 * @date: 2025/5/24 9:03
 * @version: 1.0
 */
@RestController
@RequestMapping("/shop/type")
public class TbTypeController {

    @Autowired
    TbTypeService tbTypeService;


    /**
     * @param tbType:
     * @return Result
     * @author :杨珂
     * @description 添加产品分类
     * @date 2025/5/24 9:05
     */

    @PostMapping("/addType")
    public Result addType(@RequestBody TbType tbType) {
        return tbTypeService.addType(tbType);
    }

    @PostMapping("/delType/{typeId}")
    public Result delType(@PathVariable("typeId") Integer typeId) {
        return tbTypeService.delType(typeId);
    }

    /**
     * @param :
     * @return Result
     * @author :杨珂
     * @description 获取商品分类的树
     * @date 2025/5/24 9:20
     */
    @GetMapping
    public Result getTypeList() {
        return tbTypeService.getTypeList();
    }

    /**
     * @param :
     * @return Result
     * @author :杨珂
     * @description 显示或者隐藏
     * @date 2025/5/26 14:07
     */
    @PostMapping("/setTypeStatus/{typeId}/{typeStatus}")
    public Result setTypeStatus(@PathVariable("typeId") Integer typeId, @PathVariable("typeStatus") Integer typeStatus) {
        return tbTypeService.setTypeStatus(typeId, typeStatus);
    }

    /**
     * @param typeId:
     * @return Result
     * @author :杨珂
     * @description 根据ID删除商品类型信息
     * @date 2025/5/26 18:37
     */
    @PostMapping("/delTypeById/{typeId}")
    public Result delTypeById(@PathVariable("typeId") Integer typeId) {
        return tbTypeService.delTypeById(typeId);
    }

    /**
     * @param file:
     * @return Result
     * @author :杨珂
     * @description 类型图片上传
     * @date 2025/5/26 14:59
     */
    @PostMapping("/uploadFile")
    public Result uploadFile(@RequestPart("file") MultipartFile file) {
        return tbTypeService.uploadFile(file);
    }

    /**
     * @param tbType:
     * @return Result
     * @author :杨珂
     * @description 修改商品类型信息
     * @date 2025/5/26 18:37
     */
    @PostMapping("/updateType")
    public Result updateType(@RequestBody TbType tbType) {
        return tbTypeService.updateType(tbType);
    }

    /**
     * @param :
     * @return Result
     * @author :杨珂
     * @description 用于下拉框
     * @date 2025/5/24 9:20
     */
    @PostMapping("/getSelectTypeList")
    public Result getSelectTypeList() {
        return tbTypeService.getSelectTypeList();
    }

}
